package com.rainman.simpleredis.demo.controller;

import com.rainman.simpleredis.core.SimpleRedis;
import com.rainman.simpleredis.core.scheduled.ScheduledInfo;
import com.rainman.simpleredis.core.scheduled.SimpleScheduledWorkerInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 测试动态定时器
 *
 */
@RestController
public class DemoSchController {

    @Autowired
    SimpleRedis simpleRedis;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/sch")
    public String sch(Long id)   {

        simpleRedis.addSchWorker(new SimpleScheduledWorkerInterface() {
            @Override
            public void doWork() {

                try {
                    Thread.sleep(3000);
                    System.out.println(System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public String key() {
                return "schTest"+id;
            }

            @Override
            public ScheduledInfo info() {
                return ScheduledInfo.buildRate(2000L);
            }
        });

        return id+"";
    }

}
